﻿/**************************************************
* 版权所有:Copyright (C) 
* 作    者:蔡海翔
* 创建日期:2014/6/16 13:55:49
* 描    述:
* 修改日期:
* 修改内容:
****************************************************/

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataEntity;

namespace DataAccess
{
    public class DatabaseInitializer
    {
    }
    /// <summary>
    /// 如果数据不存在进行创建
    /// </summary>
    public class MyCreateDatabaseIfNotExistsInitializer : CreateDatabaseIfNotExists<DataContext>
    {
        protected override void Seed(DataContext context)
        {
            //菜单
            var DefalutSysMenus = new List<SysMenu>
                {
                             new SysMenu { ID=1, Name ="功能模块",IconCss="icon-menu-function",SortNumber="10",MenuUrl = "" ,ParentID = 0},
                              new SysMenu { ID=2, Name ="物品类别管理",IconCss="icon-menu-goodsclass",SortNumber="1001",MenuUrl = "/Goods/GoodsClassManageIndex" ,ParentID = 1},
                              new SysMenu { ID=3, Name ="物品管理",IconCss="icon-menu-goods",SortNumber="1002",MenuUrl = "/Goods/GoodsManageIndex" ,ParentID = 1},
                              new SysMenu { ID=4, Name ="入库单管理",IconCss="icon-menu-listmanage",SortNumber="1003",MenuUrl = "/ListManage/Index" ,ParentID = 1},
                               new SysMenu { ID=5, Name ="出库单管理",IconCss="icon-menu-requisition",SortNumber="1004",MenuUrl = "/RequisitionManage/Index" ,ParentID = 1},
                              new SysMenu { ID=6, Name ="库存查询",IconCss="icon-stock-query",SortNumber="1005",MenuUrl= "/StockQuery/Index" ,ParentID = 1},
                               
                             new SysMenu { ID=7, Name ="系统配置",IconCss="icon-menu-systemset",SortNumber="20",MenuUrl = "" ,ParentID = 0},
                           
                             new SysMenu { ID=8, Name ="用户管理",IconCss="icon-user-manage",SortNumber="2002",MenuUrl = "/User/Index" ,ParentID = 7}
                            
                             
                               
                                //new SysMenu { ID=8, Name ="菜单管理",IconCss="icon-menu-manage",SortNumber="2008",MenuUrl = "/Menu/Index" ,ParentID = 6},
                                  
                };

            DefalutSysMenus.ForEach(s => context.SysMenus.Add(s));
            context.SaveChanges();

            var DefalutSysUsers = new List<SysUser>
                 {
                  new SysUser{ID=1,UserName="admin",Password="/iXjfsyPYBM=",Sex=false,RealName="管理员",IsAdmin=true,BeLock=false}
                 
                 };
            DefalutSysUsers.ForEach(s => context.SysUsers.Add(s));
            context.SaveChanges();

            var DefalutSysConfigs = new List<SysConfig>
                 {
                  new SysConfig{ID=1,PurchaseBillID=0,RequisitionBillID=0,Remark="记录产生的最大编号数字"}
                 
                 };
            DefalutSysConfigs.ForEach(s => context.SysConfigs.Add(s));
            context.SaveChanges();
        }

    }

    public class MyMigrateDatabaseToLatestVersionInitializer : MigrateDatabaseToLatestVersion<DataContext, MyDbMigrationsConfiguration>
    {


    }
    public class MyDbMigrationsConfiguration : DbMigrationsConfiguration<DataContext>
    {
        public MyDbMigrationsConfiguration()
        {
            AutomaticMigrationDataLossAllowed = true;
            AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(DataContext context)
        {


        }
    }
}
